Start on compatibility with PHPTAL 1.0 (on PHP5).
[lhc/web/wiklou.git] / includes / SkinPHPTal.php
1 <?php
2 # This program is free software; you can redistribute it and/or modify
3 # it under the terms of the GNU General Public License as published by
4 # the Free Software Foundation; either version 2 of the License, or
5 # (at your option) any later version.
6 #
7 # This program is distributed in the hope that it will be useful,
8 # but WITHOUT ANY WARRANTY; without even the implied warranty of
9 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 # GNU General Public License for more details.
11 #
12 # You should have received a copy of the GNU General Public License along
13 # with this program; if not, write to the Free Software Foundation, Inc.,
14 # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
15 # http://www.gnu.org/copyleft/gpl.html
16
17 /**
18 * Generic PHPTal (http://phptal.sourceforge.net/) skin
19 * Based on Brion's smarty skin
20 * Copyright (C) Gabriel Wicke -- http://www.aulinx.de/
21 *
22 * Todo: Needs some serious refactoring into functions that correspond
23 * to the computations individual esi snippets need. Most importantly no body
24 * parsing for most of those of course.
25 *
26 * Set this in LocalSettings to enable phptal:
27 * set_include_path(get_include_path() . ":" . $IP.'/PHPTAL-NP-0.7.0/libs');
28 * $wgUsePHPTal = true;
29 *
30 * @package MediaWiki
31 */
32
33 /**
34 * This is not a valid entry point, perform no further processing unless
35 * MEDIAWIKI is defined
36 */
37 if( defined( 'MEDIAWIKI' ) ) {
38
39 require_once 'GlobalFunctions.php';
40
41 if( version_compare( phpversion(), "5.0", "lt" ) ) {
42 define( 'OLD_PHPTAL', true );
43 global $IP;
44 require_once $IP.'/PHPTAL-NP-0.7.0/libs/PHPTAL.php';
45 } else {
46 define( 'NEW_PHPTAL', true );
47 # For now, PHPTAL 1.0.x must be installed via PEAR in system dir.
48 require_once 'PEAR.php';
49 require_once 'PHPTAL.php';
50 require_once 'PHPTAL/Attribute.php';
51 require_once 'PHPTAL/Attribute/I18N/Attributes.php';
52 }
53
54 /**
55 * @todo document
56 * @package MediaWiki
57 */
58 //class MediaWiki_I18N extends PHPTAL_I18N {
59 class MediaWiki_I18N {
60 var $_context = array();
61
62 function set($varName, $value) {
63 $this->_context[$varName] = $value;
64 }
65
66 function translate($value) {
67 $value = wfMsg( $value );
68 // interpolate variables
69 while (preg_match('/\$([0-9]*?)/sm', $value, $m)) {
70 list($src, $var) = $m;
71 wfSuppressWarnings();
72 $varValue = $this->_context[$var];
73 wfRestoreWarnings();
74 $value = str_replace($src, $varValue, $value);
75 }
76 return $value;
77 }
78
79 /* For PHPTAL 1.0: */
80 function setLanguage( $langCode ) {
81 }
82
83 function setDomain( $domain ) {
84 }
85
86 function setVar( $key, $value ) {
87 $this->set( $key, $value );
88 }
89 }
90 /**
91 *
92 * @package MediaWiki
93 */
94 class SkinPHPTal extends Skin {
95 /**#@+
96 * @access private
97 */
98
99 /**
100 * Name of our skin, set in initPage()
101 * It probably need to be all lower case.
102 */
103 var $skinname;
104
105 /**
106 * Stylesheets set to use
107 * Sub directory in ./skins/ where various stylesheets are located
108 */
109 var $stylename;
110
111 /**
112 * PHPTal template to be used.
113 * '.pt' will be automaticly added to it on PHPTAL object creation
114 */
115 var $template;
116
117 /**#@-*/
118
119 /** */
120 function initPage( &$out ) {
121 parent::initPage( $out );
122 $this->skinname = 'monobook';
123 $this->stylename = 'monobook';
124 $this->template = 'MonoBook';
125 }
126
127 /**
128 * If using PHPTAL 0.7 on PHP 4.x, return a PHPTAL template object.
129 * If using PHPTAL 1.0 on PHP 5.x, return a bridge object.
130 * @return object
131 * @access private
132 */
133 function &setupTemplate( $file, $repository=false, $cache_dir=false ) {
134 if( NEW_PHPTAL ) {
135 return new PHPTAL_version_bridge( $file, $repository, $cache_dir );
136 } else {
137 return new PHPTAL( $file, $repository, $cache_dir );
138 }
139 }
140
141 /**
142 * initialize various variables and generate the template
143 */
144 function outputPage( &$out ) {
145 global $wgTitle, $wgArticle, $wgUser, $wgLang, $wgContLang, $wgOut;
146 global $wgScript, $wgStylePath, $wgLanguageCode, $wgContLanguageCode, $wgUseNewInterlanguage;
147 global $wgMimeType, $wgOutputEncoding, $wgUseDatabaseMessages, $wgRequest;
148 global $wgDisableCounters, $wgLogo, $action, $wgFeedClasses, $wgSiteNotice;
149 global $wgMaxCredits, $wgShowCreditsIfMax;
150
151 extract( $wgRequest->getValues( 'oldid', 'diff' ) );
152
153 $this->initPage( $out );
154 $tpl =& $this->setupTemplate( $this->template . '.pt', 'skins' );
155
156 #if ( $wgUseDatabaseMessages ) { // uncomment this to fall back to GetText
157 $tpl->setTranslator(new MediaWiki_I18N());
158 #}
159
160 $this->thispage = $wgTitle->getPrefixedDbKey();
161 $this->thisurl = $wgTitle->getPrefixedURL();
162 $this->loggedin = $wgUser->getID() != 0;
163 $this->iscontent = ($wgTitle->getNamespace() != Namespace::getSpecial() );
164 $this->iseditable = ($this->iscontent and !($action == 'edit' or $action == 'submit'));
165 $this->username = $wgUser->getName();
166 $this->userpage = $wgContLang->getNsText( Namespace::getUser() ) . ":" . $wgUser->getName();
167 $this->userpageUrlDetails = $this->makeUrlDetails($this->userpage);
168
169 $this->usercss = $this->userjs = $this->userjsprev = false;
170 $this->setupUserCssJs();
171
172 $this->titletxt = $wgTitle->getPrefixedText();
173
174 $tpl->set( 'title', $wgOut->getPageTitle() );
175 $tpl->set( 'pagetitle', $wgOut->getHTMLTitle() );
176
177 $tpl->setRef( "thispage", $this->thispage );
178 $subpagestr = $this->subPageSubtitle();
179 $tpl->set(
180 'subtitle', !empty($subpagestr)?
181 '<span class="subpages">'.$subpagestr.'</span>'.$out->getSubtitle():
182 $out->getSubtitle()
183 );
184 $undelete = $this->getUndeleteLink();
185 $tpl->set(
186 "undelete", !empty($undelete)?
187 '<span class="subpages">'.$undelete.'</span>':
188 ''
189 );
190
191 $tpl->set( 'catlinks', $this->getCategories());
192 if( $wgOut->isSyndicated() ) {
193 $feeds = array();
194 foreach( $wgFeedClasses as $format => $class ) {
195 $feeds[$format] = array(
196 'text' => $format,
197 'href' => $wgRequest->appendQuery( "feed=$format" ),
198 'ttip' => wfMsg('tooltip-'.$format)
199 );
200 }
201 $tpl->setRef( 'feeds', $feeds );
202 } else {
203 $tpl->set( 'feeds', false );
204 }
205 $tpl->setRef( 'mimetype', $wgMimeType );
206 $tpl->setRef( 'charset', $wgOutputEncoding );
207 $tpl->set( 'headlinks', $out->getHeadLinks() );
208 $tpl->setRef( 'wgScript', $wgScript );
209 $tpl->setRef( 'skinname', $this->skinname );
210 $tpl->setRef( 'stylename', $this->stylename );
211 $tpl->setRef( 'loggedin', $this->loggedin );
212 $tpl->set('nsclass', 'ns-'.$wgTitle->getNamespace());
213 $tpl->set('notspecialpage', $wgTitle->getNamespace() != NS_SPECIAL);
214 /* XXX currently unused, might get useful later
215 $tpl->set( "editable", ($wgTitle->getNamespace() != NS_SPECIAL ) );
216 $tpl->set( "exists", $wgTitle->getArticleID() != 0 );
217 $tpl->set( "watch", $wgTitle->userIsWatching() ? "unwatch" : "watch" );
218 $tpl->set( "protect", count($wgTitle->getRestrictions()) ? "unprotect" : "protect" );
219 $tpl->set( "helppage", wfMsg('helppage'));
220 $tpl->set( "sysop", $wgUser->isSysop() );
221 */
222 $tpl->set( 'searchaction', $this->escapeSearchLink() );
223 $tpl->setRef( 'stylepath', $wgStylePath );
224 $tpl->setRef( 'logopath', $wgLogo );
225 $tpl->setRef( "lang", $wgContLanguageCode );
226 $tpl->set( 'dir', $wgContLang->isRTL() ? "rtl" : "ltr" );
227 $tpl->set( 'rtl', $wgContLang->isRTL() );
228 $tpl->set( 'langname', $wgContLang->getLanguageName( $wgContLanguageCode ) );
229 $tpl->setRef( 'username', $this->username );
230 $tpl->setRef( 'userpage', $this->userpage);
231 $tpl->setRef( 'userpageurl', $this->userpageUrlDetails['href']);
232 $tpl->setRef( 'usercss', $this->usercss);
233 $tpl->setRef( 'userjs', $this->userjs);
234 $tpl->setRef( 'userjsprev', $this->userjsprev);
235 if($this->loggedin) {
236 $tpl->set( 'jsvarurl', $this->makeUrl('-','action=raw&smaxage=0&gen=js') );
237 } else {
238 $tpl->set( 'jsvarurl', $this->makeUrl('-','action=raw&gen=js') );
239 }
240 if( $wgUser->getNewtalk() ) {
241 $usertitle = Title::newFromText( $this->userpage );
242 $usertalktitle = $usertitle->getTalkPage();
243 if($usertalktitle->getPrefixedDbKey() != $this->thispage){
244
245 $ntl = wfMsg( 'newmessages',
246 $this->makeKnownLink(
247 $wgContLang->getNsText( Namespace::getTalk( Namespace::getUser() ) )
248 . ':' . $this->username,
249 wfMsg('newmessageslink') )
250 );
251 # Disable Cache
252 $wgOut->setSquidMaxage(0);
253 }
254 } else {
255 $ntl = '';
256 }
257
258 $tpl->setRef( 'newtalk', $ntl );
259 $tpl->setRef( 'skin', $this);
260 $tpl->set( 'logo', $this->logoText() );
261 if ( $wgOut->isArticle() and (!isset( $oldid ) or isset( $diff )) and 0 != $wgArticle->getID() ) {
262 if ( !$wgDisableCounters ) {
263 $viewcount = $wgLang->formatNum( $wgArticle->getCount() );
264 if ( $viewcount ) {
265 $tpl->set('viewcount', wfMsg( "viewcount", $viewcount ));
266 }
267 }
268 $tpl->set('lastmod', $this->lastModified());
269 $tpl->set('copyright',$this->getCopyright());
270
271 $this->credits = false;
272
273 if (isset($wgMaxCredits) && $wgMaxCredits != 0) {
274 require_once("Credits.php");
275 $this->credits = getCredits($wgArticle, $wgMaxCredits, $wgShowCreditsIfMax);
276 }
277
278 $tpl->setRef( 'credits', $this->credits );
279
280 } elseif ( isset( $oldid ) && !isset( $diff ) ) {
281 $tpl->set('copyright', $this->getCopyright());
282 $tpl->set('viewcount', false);
283 $tpl->set('lastmod', false);
284 $tpl->set('credits', false);
285 } else {
286 $tpl->set('copyright', false);
287 $tpl->set('viewcount', false);
288 $tpl->set('lastmod', false);
289 $tpl->set('credits', false);
290 }
291
292 $tpl->set( 'copyrightico', $this->getCopyrightIcon() );
293 $tpl->set( 'poweredbyico', $this->getPoweredBy() );
294 $tpl->set( 'disclaimer', $this->disclaimerLink() );
295 $tpl->set( 'about', $this->aboutLink() );
296
297 $tpl->setRef( 'debug', $out->mDebugtext );
298 $tpl->set( 'reporttime', $out->reportTime() );
299 $tpl->set( 'sitenotice', $wgSiteNotice );
300
301 $printfooter = "<div class=\"printfooter\">\n" . $this->printSource() . "</div>\n";
302 $out->mBodytext .= $printfooter ;
303 $tpl->setRef( 'bodytext', $out->mBodytext );
304
305 $language_urls = array();
306 foreach( $wgOut->getLanguageLinks() as $l ) {
307 $nt = Title::newFromText( $l );
308 $language_urls[] = array('href' => $nt->getFullURL(),
309 'text' => ($wgContLang->getLanguageName( $nt->getInterwiki()) != ''?$wgContLang->getLanguageName( $nt->getInterwiki()) : $l),
310 'class' => $wgContLang->isRTL() ? 'rtl' : 'ltr');
311 }
312 if(count($language_urls)) {
313 $tpl->setRef( 'language_urls', $language_urls);
314 } else {
315 $tpl->set('language_urls', false);
316 }
317 $tpl->set('personal_urls', $this->buildPersonalUrls());
318 $content_actions = $this->buildContentActionUrls();
319 $tpl->setRef('content_actions', $content_actions);
320 // XXX: attach this from javascript, same with section editing
321 if($this->iseditable && $wgUser->getOption("editondblclick") )
322 {
323 $tpl->set('body_ondblclick', 'document.location = "' .$content_actions['edit']['href'] .'";');
324 } else {
325 $tpl->set('body_ondblclick', false);
326 }
327 $tpl->set( 'nav_urls', $this->buildNavUrls() );
328
329 // execute template
330 $res = $tpl->execute();
331 // result may be an error
332 if (PEAR::isError($res)) {
333 echo $res->toString(), "\n";
334 } else {
335 echo $res;
336 }
337
338 }
339
340 /**
341 * build array of urls for personal toolbar
342 */
343 function buildPersonalUrls() {
344 /* set up the default links for the personal toolbar */
345 global $wgShowIPinHeader;
346 $personal_urls = array();
347 if ($this->loggedin) {
348 $personal_urls['userpage'] = array(
349 'text' => $this->username,
350 'href' => &$this->userpageUrlDetails['href'],
351 'class' => $this->userpageUrlDetails['exists']?false:'new'
352 );
353 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage);
354 $personal_urls['mytalk'] = array(
355 'text' => wfMsg('mytalk'),
356 'href' => &$usertalkUrlDetails['href'],
357 'class' => $usertalkUrlDetails['exists']?false:'new'
358 );
359 $personal_urls['preferences'] = array(
360 'text' => wfMsg('preferences'),
361 'href' => $this->makeSpecialUrl('Preferences')
362 );
363 $personal_urls['watchlist'] = array(
364 'text' => wfMsg('watchlist'),
365 'href' => $this->makeSpecialUrl('Watchlist')
366 );
367 $personal_urls['mycontris'] = array(
368 'text' => wfMsg('mycontris'),
369 'href' => $this->makeSpecialUrl('Contributions','target=' . urlencode( $this->username ) )
370 );
371 $personal_urls['logout'] = array(
372 'text' => wfMsg('userlogout'),
373 'href' => $this->makeSpecialUrl('Userlogout','returnto=' . $this->thisurl )
374 );
375 } else {
376 if( $wgShowIPinHeader && isset( $_COOKIE[ini_get("session.name")] ) ) {
377 $personal_urls['anonuserpage'] = array(
378 'text' => $this->username,
379 'href' => &$this->userpageUrlDetails['href'],
380 'class' => $this->userpageUrlDetails['exists']?false:'new'
381 );
382 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage);
383 $personal_urls['anontalk'] = array(
384 'text' => wfMsg('anontalk'),
385 'href' => &$usertalkUrlDetails['href'],
386 'class' => $usertalkUrlDetails['exists']?false:'new'
387 );
388 $personal_urls['anonlogin'] = array(
389 'text' => wfMsg('userlogin'),
390 'href' => $this->makeSpecialUrl('Userlogin', 'returnto=' . $this->thisurl )
391 );
392 } else {
393
394 $personal_urls['login'] = array(
395 'text' => wfMsg('userlogin'),
396 'href' => $this->makeSpecialUrl('Userlogin', 'returnto=' . $this->thisurl )
397 );
398 }
399 }
400
401 return $personal_urls;
402 }
403
404 /**
405 * an array of edit links by default used for the tabs
406 */
407 function buildContentActionUrls () {
408 global $wgTitle, $wgUser, $wgOut, $wgRequest, $wgUseValidation;
409 $action = $wgRequest->getText( 'action' );
410 $section = $wgRequest->getText( 'section' );
411 $oldid = $wgRequest->getVal( 'oldid' );
412 $diff = $wgRequest->getVal( 'diff' );
413 $content_actions = array();
414
415 if( $this->iscontent and !$wgOut->isQuickbarSuppressed() ) {
416
417 $nskey = $this->getNameSpaceKey();
418 $is_active = !Namespace::isTalk( $wgTitle->getNamespace()) ;
419 if ( $action == 'validate' ) $is_active = false ; # Show article tab deselected when validating
420 $content_actions[$nskey] = array('class' => ($is_active) ? 'selected' : false,
421 'text' => wfMsg($nskey),
422 'href' => $this->makeArticleUrl($this->thispage));
423
424 /* set up the classes for the talk link */
425 $talk_class = (Namespace::isTalk( $wgTitle->getNamespace()) ? 'selected' : false);
426 $talktitle = Title::newFromText( $this->titletxt );
427 $talktitle = $talktitle->getTalkPage();
428 $this->checkTitle($talktitle, $this->titletxt);
429 if($talktitle->getArticleId() != 0) {
430 $content_actions['talk'] = array(
431 'class' => $talk_class,
432 'text' => wfMsg('talk'),
433 'href' => $this->makeTalkUrl($this->titletxt)
434 );
435 } else {
436 $content_actions['talk'] = array(
437 'class' => $talk_class?$talk_class.' new':'new',
438 'text' => wfMsg('talk'),
439 'href' => $this->makeTalkUrl($this->titletxt,'action=edit')
440 );
441 }
442
443 if ( $wgTitle->userCanEdit() ) {
444 $oid = ( $oldid && ! isset( $diff ) ) ? '&oldid='.$oldid : false;
445 $istalk = ( Namespace::isTalk( $wgTitle->getNamespace()) );
446 $istalkclass = $istalk?' istalk':'';
447 $content_actions['edit'] = array(
448 'class' => ((($action == 'edit' or $action == 'submit') and $section != 'new') ? 'selected' : '').$istalkclass,
449 'text' => wfMsg('edit'),
450 'href' => $this->makeUrl($this->thispage, 'action=edit'.$oid)
451 );
452 if ( $istalk ) {
453 $content_actions['addsection'] = array(
454 'class' => $section == 'new'?'selected':false,
455 'text' => wfMsg('addsection'),
456 'href' => $this->makeUrl($this->thispage, 'action=edit&section=new')
457 );
458 }
459 } else {
460 $oid = ( $oldid && ! isset( $diff ) ) ? '&oldid='.$oldid : '';
461 $content_actions['viewsource'] = array('class' => ($action == 'edit') ? 'selected' : false,
462 'text' => wfMsg('viewsource'),
463 'href' => $this->makeUrl($this->thispage, 'action=edit'.$oid));
464 }
465
466 if ( $wgTitle->getArticleId() ) {
467
468 $content_actions['history'] = array('class' => ($action == 'history') ? 'selected' : false,
469 'text' => wfMsg('history_short'),
470 'href' => $this->makeUrl($this->thispage, 'action=history'));
471
472 # XXX: is there a rollback action anywhere or is it planned?
473 # Don't recall where i got this from...
474 /*if( $wgUser->getNewtalk() ) {
475 $content_actions['rollback'] = array('class' => ($action == 'rollback') ? 'selected' : false,
476 'text' => wfMsg('rollback_short'),
477 'href' => $this->makeUrl($this->thispage, 'action=rollback'),
478 'ttip' => wfMsg('tooltip-rollback'),
479 'akey' => wfMsg('accesskey-rollback'));
480 }*/
481
482 if($wgUser->isSysop()){
483 if(!$wgTitle->isProtected()){
484 $content_actions['protect'] = array(
485 'class' => ($action == 'protect') ? 'selected' : false,
486 'text' => wfMsg('protect'),
487 'href' => $this->makeUrl($this->thispage, 'action=protect')
488 );
489
490 } else {
491 $content_actions['unprotect'] = array(
492 'class' => ($action == 'unprotect') ? 'selected' : false,
493 'text' => wfMsg('unprotect'),
494 'href' => $this->makeUrl($this->thispage, 'action=unprotect')
495 );
496 }
497 $content_actions['delete'] = array(
498 'class' => ($action == 'delete') ? 'selected' : false,
499 'text' => wfMsg('delete'),
500 'href' => $this->makeUrl($this->thispage, 'action=delete')
501 );
502 }
503 if ( $wgUser->getID() != 0 ) {
504 if ( $wgTitle->userCanEdit()) {
505 $content_actions['move'] = array('class' => ($wgTitle->getDbKey() == 'Movepage' and $wgTitle->getNamespace == Namespace::getSpecial()) ? 'selected' : false,
506 'text' => wfMsg('move'),
507 'href' => $this->makeSpecialUrl('Movepage', 'target='. urlencode( $this->thispage ))
508 );
509 } else {
510 $content_actions['move'] = array('class' => 'inactive',
511 'text' => wfMsg('move'),
512 'href' => false);
513
514 }
515 }
516 } else {
517 //article doesn't exist or is deleted
518 if($wgUser->isSysop()){
519 if( $n = $wgTitle->isDeleted() ) {
520 $content_actions['delete'] = array(
521 'class' => false,
522 'text' => wfMsg( "undelete_short", $n ),
523 'href' => $this->makeSpecialUrl('Undelete/'.$this->thispage)
524 );
525 }
526 }
527 }
528
529 if ( $wgUser->getID() != 0 and $action != 'submit' ) {
530 if( !$wgTitle->userIsWatching()) {
531 $content_actions['watch'] = array('class' => ($action == 'watch' or $action == 'unwatch') ? 'selected' : false,
532 'text' => wfMsg('watch'),
533 'href' => $this->makeUrl($this->thispage, 'action=watch'));
534 } else {
535 $content_actions['unwatch'] = array('class' => ($action == 'unwatch' or $action == 'watch') ? 'selected' : false,
536 'text' => wfMsg('unwatch'),
537 'href' => $this->makeUrl($this->thispage, 'action=unwatch'));
538 }
539 }
540
541 # Show validate tab
542 if ( $wgUseValidation && $wgTitle->getArticleId() && $wgTitle->getNamespace() == 0 ) {
543 global $wgArticle ;
544 $article_time = "&timestamp=" . $wgArticle->mTimestamp ;
545 $content_actions['validate'] = array('class' => ($action == 'validate') ? 'selected' : false ,
546 'text' => wfMsg('val_tab'),
547 'href' => $this->makeUrl($this->thispage, 'action=validate'.$article_time));
548 }
549
550 } else {
551 /* show special page tab */
552
553 $content_actions['article'] = array('class' => 'selected',
554 'text' => wfMsg('specialpage'),
555 'href' => false);
556 }
557
558 return $content_actions;
559 }
560
561 /**
562 * build array of common navigation links
563 */
564 function buildNavUrls () {
565 global $wgTitle, $wgUser, $wgRequest;
566 global $wgSiteSupportPage, $wgDisableUploads;
567
568 $action = $wgRequest->getText( 'action' );
569 $oldid = $wgRequest->getVal( 'oldid' );
570 $diff = $wgRequest->getVal( 'diff' );
571 // XXX: remove htmlspecialchars when tal:attributes works with i18n:attributes
572 $nav_urls = array();
573 $nav_urls['mainpage'] = array('href' => htmlspecialchars( $this->makeI18nUrl('mainpage')));
574 $nav_urls['randompage'] = array('href' => htmlspecialchars( $this->makeSpecialUrl('Randompage')));
575 $nav_urls['recentchanges'] = array('href' => htmlspecialchars( $this->makeSpecialUrl('Recentchanges')));
576 $nav_urls['currentevents'] = (wfMsg('currentevents') != '-') ? array('href' => htmlspecialchars( $this->makeI18nUrl('currentevents'))) : false;
577 $nav_urls['portal'] = (wfMsg('portal') != '-') ? array('href' => htmlspecialchars( $this->makeI18nUrl('portal-url'))) : false;
578 $nav_urls['bugreports'] = array('href' => htmlspecialchars( $this->makeI18nUrl('bugreportspage')));
579 // $nav_urls['sitesupport'] = array('href' => htmlspecialchars( $this->makeI18nUrl('sitesupportpage')));
580 $nav_urls['sitesupport'] = array('href' => htmlspecialchars( $wgSiteSupportPage));
581 $nav_urls['help'] = array('href' => htmlspecialchars( $this->makeI18nUrl('helppage')));
582 if( $this->loggedin && !$wgDisableUploads ) {
583 $nav_urls['upload'] = array('href' => htmlspecialchars( $this->makeSpecialUrl('Upload')));
584 } else {
585 $nav_urls['upload'] = false;
586 }
587 $nav_urls['specialpages'] = array('href' => htmlspecialchars( $this->makeSpecialUrl('Specialpages')));
588
589 if( $wgTitle->getNamespace() != NS_SPECIAL) {
590 $nav_urls['whatlinkshere'] = array('href' => htmlspecialchars( $this->makeSpecialUrl('Whatlinkshere', 'target='.urlencode( $this->thispage ))));
591 $nav_urls['recentchangeslinked'] = array('href' => htmlspecialchars( $this->makeSpecialUrl('Recentchangeslinked', 'target='.urlencode( $this->thispage ))));
592 }
593
594 if( $wgTitle->getNamespace() == NS_USER || $wgTitle->getNamespace() == NS_USER_TALK ) {
595 $id = User::idFromName($wgTitle->getText());
596 $ip = User::isIP($wgTitle->getText());
597 } else {
598 $id = 0;
599 $ip = false;
600 }
601
602 if($id || $ip) { # both anons and non-anons have contri list
603 $nav_urls['contributions'] = array(
604 'href' => htmlspecialchars( $this->makeSpecialUrl('Contributions', "target=" . $wgTitle->getPartialURL() ) )
605 );
606 } else {
607 $nav_urls['contributions'] = false;
608 }
609 $nav_urls['emailuser'] = false;
610 if ( 0 != $wgUser->getID() ) { # show only to signed in users
611 if($id) { # can only email non-anons
612 $nav_urls['emailuser'] = array(
613 'href' => htmlspecialchars( $this->makeSpecialUrl('Emailuser', "target=" . $wgTitle->getPartialURL() ) )
614 );
615 }
616 }
617
618 return $nav_urls;
619 }
620
621 /**
622 * Generate strings used for xml 'id' names
623 */
624 function getNameSpaceKey () {
625 global $wgTitle;
626 switch ($wgTitle->getNamespace()) {
627 case NS_MAIN:
628 case NS_TALK:
629 return 'nstab-main';
630 case NS_USER:
631 case NS_USER_TALK:
632 return 'nstab-user';
633 case NS_MEDIA:
634 return 'nstab-media';
635 case NS_SPECIAL:
636 return 'nstab-special';
637 case NS_PROJECT:
638 case NS_PROJECT_TALK:
639 return 'nstab-wp';
640 case NS_IMAGE:
641 case NS_IMAGE_TALK:
642 return 'nstab-image';
643 case NS_MEDIAWIKI:
644 case NS_MEDIAWIKI_TALK:
645 return 'nstab-mediawiki';
646 case NS_TEMPLATE:
647 case NS_TEMPLATE_TALK:
648 return 'nstab-template';
649 case NS_HELP:
650 case NS_HELP_TALK:
651 return 'nstab-help';
652 case NS_CATEGORY:
653 case NS_CATEGORY_TALK:
654 return 'nstab-category';
655 default:
656 return 'nstab-main';
657 }
658 }
659
660
661 /**
662 * @access private
663 */
664 function setupUserCssJs () {
665 global $wgRequest, $wgTitle;
666 $action = $wgRequest->getText('action');
667 # generated css
668 $this->usercss = '@import "'.$this->makeUrl('-','action=raw&gen=css').'";'."\n";
669
670 if( $this->loggedin ) {
671 if($wgTitle->isCssSubpage() and $action == 'submit' and $wgTitle->userCanEditCssJsSubpage()) {
672 # generated css
673 $this->usercss = '@import "'.$this->makeUrl('-','action=raw&smaxage=0&maxage=0&gen=css').'";'."\n";
674 // css preview
675 $this->usercss .= $wgRequest->getText('wpTextbox1');
676 } else {
677 # generated css
678 $this->usercss .= '@import "'.$this->makeUrl('-','action=raw&smaxage=0&gen=css').'";'."\n";
679 # import user stylesheet
680 $this->usercss .= '@import "'.
681 $this->makeUrl($this->userpage.'/'.$this->skinname.'.css', 'action=raw&ctype=text/css').'";'."\n";
682 }
683 if($wgTitle->isJsSubpage() and $action == 'submit' and $wgTitle->userCanEditCssJsSubpage()) {
684 # XXX: additional security check/prompt?
685 $this->userjsprev = $wgRequest->getText('wpTextbox1');
686 } else {
687 $this->userjs = $this->makeUrl($this->userpage.'/'.$this->skinname.'.js', 'action=raw&ctype=text/javascript&dontcountme=s');
688 }
689 }
690 }
691
692 /**
693 * returns css with user-specific options
694 */
695 function getUserStylesheet() {
696 global $wgUser, $wgRequest, $wgTitle, $wgContLang, $wgSquidMaxage, $wgStylePath;
697 $action = $wgRequest->getText('action');
698 $maxage = $wgRequest->getText('maxage');
699 $s = "/* generated user stylesheet */\n";
700 if($wgContLang->isRTL()) $s .= '@import "'.$wgStylePath.'/'.$this->stylename.'/rtl.css";'."\n";
701 $s .= '@import "'.
702 $this->makeNSUrl(ucfirst($this->skinname).'.css', 'action=raw&ctype=text/css&smaxage='.$wgSquidMaxage, NS_MEDIAWIKI)."\";\n";
703 if($wgUser->getID() != 0) {
704 if ( 1 == $wgUser->getOption( "underline" ) ) {
705 $s .= "a { text-decoration: underline; }\n";
706 } else {
707 $s .= "a { text-decoration: none; }\n";
708 }
709 }
710 if ( 1 != $wgUser->getOption( "highlightbroken" ) ) {
711 $s .= "a.new, #quickbar a.new { color: #CC2200; }\n";
712 }
713 if ( 1 == $wgUser->getOption( "justify" ) ) {
714 $s .= "#bodyContent { text-align: justify; }\n";
715 }
716 return $s;
717 }
718
719 /**
720 *
721 */
722 function getUserJs() {
723 global $wgUser, $wgStylePath;
724 $s = '/* generated javascript */';
725 $s .= "var skin = '{$this->skinname}';\nvar stylepath = '{$wgStylePath}';";
726 $s .= '/* MediaWiki:'.ucfirst($this->skinname)." */\n";
727 $s .= wfMsg(ucfirst($this->skinname).'.js');
728 return $s;
729 }
730 }
731
732 class PHPTAL_version_bridge {
733 function PHPTAL_version_bridge( $file, $repository=false, $cache_dir=false ) {
734 $this->tpl =& new PHPTAL( $file );
735 if( $repository ) {
736 $this->tpl->setTemplateRepository( $repository );
737 }
738 }
739
740 function set( $name, $value ) {
741 $this->tpl->$name = $value;
742 }
743
744 function setRef($name, &$value) {
745 $this->set( $name, $value );
746 }
747
748 function setTranslator( &$t ) {
749 $this->tpl->setTranslator( $t );
750 }
751
752 function execute() {
753 /*
754 try {
755 */
756 return $this->tpl->execute();
757 /*
758 }
759 catch (Exception $e) {
760 echo "<div class='error' style='background: white; white-space: pre; position: absolute; z-index: 9999; border: solid 2px black; padding: 4px;'>We caught an exception...\n ";
761 echo $e;
762 echo "</div>";
763 }
764 */
765 }
766 }
767
768 } // end of if( defined( 'MEDIAWIKI' ) )
769 ?>